package main

import (
	"fmt"
	"time"
)

func main() {

	go test1() // 输出：this is test 1
	go test2() //  this is test 2; test 2 is panic
	go test3() //this is test3

	func() {
		for {
			time.Sleep(time.Second * 2)
		}
	}()
}

func test1() {
	for {
		time.Sleep(time.Second * 2)
		fmt.Println("this is test 1")
	}

}

func test2() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("**test2**")
			fmt.Println(err)
			fmt.Println("************")
		}
	}()
	fmt.Println("this is test 2")
	test4()
}

func test3() {
	fmt.Println("this is test 3")
}

func test4() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("**test4**")
			fmt.Println(err)
			fmt.Println("*********")
		}
	}()
	panic("test 4 is panic")
}
